package com.lft.examsys.util;


import org.joda.time.DateTime;

import java.util.Date;

/**
 * @author ：Qingchen
 * @date ：Created in 2022/3/28 14:31
 * @description：时间构造器
 * @modified By：
 * @version: $
 */
public class DateTimeUtil {
    public static String secToTime(long seconds) {
        long hour = seconds / 3600;
        long minute = (seconds - hour * 3600) / 60;
        long second = (seconds - hour * 3600 - minute * 60);

        StringBuffer sb = new StringBuffer();
        if (hour > 0) {
            sb.append(hour + "小时");
        }
        if (minute > 0) {
            sb.append(minute + "分");
        }
        if (second > 0) {
            sb.append(second + "秒");
        }
        if (second == 0) {
            sb.append("<1秒");
        }
        return sb.toString();
    }

    public static String paperStatus(Date begin, Integer limitation) {
        DateTime dateTime = new DateTime(begin);
        //TODO 未开始
        if (dateTime.isAfterNow()) return "未开始";
        DateTime endTime = new DateTime(dateTime.plusMinutes(limitation));
        if (dateTime.isBeforeNow() && endTime.isAfterNow()) return "已开始";
        dateTime.plusMinutes(limitation);
        if (dateTime.isBeforeNow()) return "已结束";
        return "";
    }
}